<?php
		class FRM_Tools_Translit
		
		{
			
			static function ConvertString($str,$length=256){
				
           	$Letters = array();
            $Letters["а"] = "a";
            $Letters["б"] = "b";
            $Letters["в"] = "v";
            $Letters["г"] = "g";
            $Letters["д"] = "d";
            $Letters["е"] = "e";
            $Letters["ё"] = "e";
            $Letters["ж"] = "zh";
            $Letters["з"] = "z";
            $Letters["и"] = "i";
            $Letters["й"] = "y";
            $Letters["к"] = "k";
            $Letters["л"] = "l";
            $Letters["м"] = "m";
            $Letters["н"] = "n";
            $Letters["о"] = "o";
            $Letters["п"] = "p";
            $Letters["р"] = "r";
            $Letters["с"] = "s";
            $Letters["т"] = "t";
            $Letters["у"] = "u";
            $Letters["ф"] = "f";
            $Letters["х"] = "h";
            $Letters["ц"] = "c";
            $Letters["ч"] = "ch";
            $Letters["ш"] = "sh";
            $Letters["щ"] = "sch";
            $Letters["ъ"] = "";
            $Letters["ы"] = "y";
            $Letters["ь"] = "";
            $Letters["э"] = "e";
            $Letters["ю"] = "yu";
            $Letters["я"] = "ya";
			$Letters["А"] = "a";
            $Letters["Б"] = "b";
            $Letters["В"] = "v";
            $Letters["Г"] = "g";
            $Letters["Д"] = "d";
            $Letters["Е"] = "e";
            $Letters["Ё"] = "e";
            $Letters["Ж"] = "zh";
            $Letters["З"] = "z";
            $Letters["И"] = "i";
            $Letters["Й"] = "y";
            $Letters["К"] = "k";
            $Letters["Л"] = "l";
            $Letters["М"] = "m";
            $Letters["Н"] = "n";
            $Letters["О"] = "o";
            $Letters["П"] = "p";
            $Letters["Р"] = "r";
            $Letters["С"] = "s";
            $Letters["Т"] = "t";
            $Letters["У"] = "u";
            $Letters["Ф"] = "f";
            $Letters["Х"] = "h";
            $Letters["Ц"] = "c";
            $Letters["Ч"] = "ch";
            $Letters["Ш"] = "sh";
            $Letters["Щ"] = "sch";
            $Letters["Ъ"] = "";
            $Letters["Ы"] = "y";
            $Letters["Ь"] = "";
            $Letters["Э"] = "e";
            $Letters["Ю"] = "yu";
            $Letters["Я"] = "ya";
            //$Letters[" "] = "_";
            $Letters[" "] = "-";

            /* знаки припенания */
            $Letters[","] = "";
            $Letters[";"] = "";
            $Letters[":"] = "";
            $Letters["."] = "";
            $Letters["!"] = "";
            $Letters["?"] = "";
            //$Letters["-"] = "_";

            /* спецсимволы */
            $Letters["`"] = "";
            $Letters["\""] = "";
            $Letters["'"] = "";
            $Letters["%"] = "";
            $Letters["&"] = "";
            $Letters["$"] = "";
            $Letters["#"] = "";
            $Letters["/"] = "";
            $Letters["\\"] = "";

            /* немецкий */
            $Letters["a"] = "a";
            $Letters["o"] = "o";
            $Letters["?"] = "b";
            $Letters["u"] = "u";

            $new_str = "";
            //$str = @mb_strtolower($str,"UTF8");
            $str = @strtolower($str);

            foreach($Letters as $key=>$value){
                $str = str_replace($key,$value,$str);
            }
            $new_str = substr($str,0,$length);
            return $new_str;
        }
			
		static function rus2translit($string) {
			    $converter = array(
			        'а' => 'a',   'б' => 'b',   'в' => 'v',
			        'г' => 'g',   'д' => 'd',   'е' => 'e',
			        'ё' => 'e',   'ж' => 'zh',  'з' => 'z',
			        'и' => 'i',   'й' => 'y',   'к' => 'k',
			        'л' => 'l',   'м' => 'm',   'н' => 'n',
			        'о' => 'o',   'п' => 'p',   'р' => 'r',
			        'с' => 's',   'т' => 't',   'у' => 'u',
			        'ф' => 'f',   'х' => 'h',   'ц' => 'c',
			        'ч' => 'ch',  'ш' => 'sh',  'щ' => 'sch',
			        'ь' => '\'',  'ы' => 'y',   'ъ' => '',
			        'э' => 'e',   'ю' => 'yu',  'я' => 'ya',
			       
			        'А' => 'A',   'Б' => 'B',   'В' => 'V',
			        'Г' => 'G',   'Д' => 'D',   'Е' => 'E',
			        'Ё' => 'E',   'Ж' => 'Zh',  'З' => 'Z',
			        'И' => 'I',   'Й' => 'Y',   'К' => 'K',
			        'Л' => 'L',   'М' => 'M',   'Н' => 'N',
			        'О' => 'O',   'П' => 'P',   'Р' => 'R',
			        'С' => 'S',   'Т' => 'T',   'У' => 'U',
			        'Ф' => 'F',   'Х' => 'H',   'Ц' => 'C',
			        'Ч' => 'Ch',  'Ш' => 'Sh',  'Щ' => 'Sch',
			        'Ь' => '\'',  'Ы' => 'Y',   'Ъ' => '',
			        'Э' => 'E',   'Ю' => 'Yu',  'Я' => 'Ya',
			    );
			    return strtr($string, $converter);
			}
	
		}